package com.drojian.root;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Lifecycle;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import java.util.List;


public class myFragmentTitleAdapter extends FragmentStateAdapter {

    private final List<Fragment> fragmentList;
    private final List<String> titleList;

    public myFragmentTitleAdapter(@NonNull FragmentManager fragmentManager, @NonNull Lifecycle lifecycle, List<Fragment> fragmentList, List<String> titleList) {
        super(fragmentManager, lifecycle);
        this.fragmentList = fragmentList;
        this.titleList = titleList;
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
            return fragmentList == null ? null : fragmentList.get(position);
       }

    @Override
    public int getItemCount() {
        return fragmentList == null ? 0 : fragmentList.size();
    }

    public String getTabTitle(int position) {
        if (titleList != null && position < titleList.size()) {
            return titleList.get(position);
        }
        return "getTabTitle 出错啦";
    }
}